﻿#Description: delete the site collection and create the site collection with the same name and URL
#Environment: SharePoint 2010 Application Server
#Account Privilege Requirement: SharePoint Central Administrator
#Parameters: Site Name, Site Url, Site Collection Primary Administrator, Site Collection Secondary Administrator, Site Template, Web Application Url
param(
	#[string]$webAppUrl = "$(Read-Host 'Enter the web application url')",
	[string]$siteCollectionUrl = "$(Read-Host 'Enter the site Url. [e.g. /sites/newsite]')",
	[string]$siteName ="$(Read-Host 'Enter the site name')",
	[string]$siteTemplateId = "$(read-Host 'Enter the site template ID')",
	[string]$primaryAdmin = "$(Read-Host 'Enter the site collection primary administrator [e.g. intergen/stevenw]')",
	[string]$secondaryAdmin =  ""
)


#Site Definition	Site Template ID
#Team Site	STS#0
#Blank Site	STS#1
#Document Workspace	STS#2
#Blog	BLOG#0
#Group Work Site	SGS#0
#Visio Process Repository	VISPRUS#0
#Basic Meeting Workspace	MPS#0
#Blank Meeting Workspace	MPS#1
#Decision Meeting Workspace	MPS#2
#Social Meeting Workspace	MPS#3
#Multipage Meeting Workspace	MPS#4
#Assets Web Database	ACCSRV#1
#Charitable Contributions Web Database	ACCSRV#3
#Contacts Web Database	ACCSRV#41
#Issues Web Database	ACCSRV#6
#Projects Web Database	ACCSRV#5
#Document Center	BDR#0
#Records Center	OFFILE#1
#Business Intelligence Center	BICenterSite#0
#My Site Host	SPSMSITEHOST#0
#Personalization Site	SPSMSITE#0
#Enterprise Search Center	SRCHCEN#0
#Basic Search Center	SRCHCENTERLITE#0
#FAST Search Center	SRCHCENTERFAST#0
#Enterprise Wiki	ENTERWIKI#0
#Publishing Portal	BLANKINTERNETCONTAINER#0
#Publishing Site	CMSPUBLISHING#0


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 


function RecreateSiteCollection(){
	#$siteCollectionUrl = $webAppUrl + $siteUrl
	Remove-SPSite -Identity $siteCollectionUrl -Confirm:$false
	Write-Host $siteCollectionUrl " is successfully deleted." -ForegroundColor Red
	if($secondaryAdmin -eq ''){
		New-SPSite -Url $siteCollectionUrl -Template $siteTemplateId -OwnerAlias $primaryAdmin -Name $siteName
	}else{
		New-SPSite -Url $siteCollectionUrl -Template $siteTemplateId -OwnerAlias $primaryAdmin -SecondaryOwnerAlias $secondaryAdmin -Name $siteName

	}
	
		
	$culture = [System.Globalization.CultureInfo]::CreateSpecificCulture("en-NZ")
	$web = Get-SPWeb $siteCollectionUrl
	$web.Locale = $culture
	$web.Update()
	$web.Dispose()
	
	Write-Host $siteCollectionUrl " is successfully created." -ForegroundColor Green
}
RecreateSiteCollection